//
//  AppDelegate.m
//  口袋
//
//  Created by dllo on 15/5/21.
//  Copyright (c) 2015年 口袋. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "MyViewController.h"
#import "ReadViewController.h"
#import "RadioViewController.h"

#define kAppKey @"1286675123"
#define kRedirectURI @"https://api.weibo.com/oauth2/default.html"

@interface AppDelegate ()

@end

@implementation AppDelegate

@synthesize wbtoken;
@synthesize wbCurrentUserID;

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
//    [UMSocialData setAppKey:@"5566b51d67e58e306a004baf"];
    
    [WeiboSDK enableDebugMode:YES];
    [WeiboSDK registerApp:kAppKey];
    
    
    
    
    self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
    [_window setBackgroundColor:[UIColor whiteColor]];
    [_window makeKeyAndVisible];
    
    
    NSMutableArray * array = [NSMutableArray array];
    
    MainViewController * main = [[MainViewController alloc] init];
    [main.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:118/255.0 green:210/255.0 blue:245/255.0 alpha:1.0]];
    UIImageView *news = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 41)];
    [news setImage:[UIImage imageNamed:@"newstitle.png"]];
    main.navigationItem.titleView = news;

    UINavigationController * navi1 = [[UINavigationController alloc] initWithRootViewController:main];
    navi1.tabBarItem.title = @"新闻";
    navi1.tabBarItem.image = [UIImage imageNamed:@"1.png"];
    [array addObject:navi1];
    [navi1 release];
    
    
    ReadViewController * readView = [[ReadViewController alloc] init];
    UINavigationController * navi3 = [[UINavigationController alloc] initWithRootViewController:readView];
    [readView.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:118/255.0 green:210/255.0 blue:245/255.0 alpha:1.0]];
    UIImageView *read = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 41)];
    [read setImage:[UIImage imageNamed:@"hotreading.png"]];
    readView.navigationItem.titleView = read;
    navi3.tabBarItem.title = @"阅读";
    navi3.tabBarItem.image = [UIImage imageNamed:@"2.png"];
    [array addObject:navi3];
    [readView release];
    
    
    RadioViewController * radio = [[RadioViewController alloc] init];
//    [radio.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:128/255.0 green:217/255.0 blue:215/255.0 alpha:1.0]];
    UINavigationController * navi4 = [[UINavigationController alloc]
                                      initWithRootViewController:radio];
    [navi4.navigationBar setBarTintColor:[UIColor colorWithRed:118/255.0 green:210/255.0 blue:245/255.0 alpha:1.0]];
    navi4.tabBarItem.title = @"电台";
    navi4.tabBarItem.image = [UIImage imageNamed:@"3.png"];
    [array addObject:navi4];
    [radio release];
    
    MyViewController * myView = [[MyViewController alloc] init];
    //[myView.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:128/255.0 green:217/255.0 blue:215/255.0 alpha:1.0]];
    UIImageView *collect = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 41)];
    [collect setImage:[UIImage imageNamed:@"我的收藏.png"]];
    myView.navigationItem.titleView = collect;

    UINavigationController * navi2 = [[UINavigationController alloc] initWithRootViewController:myView];
    [navi2.navigationBar setBarTintColor:[UIColor colorWithRed:118/255.0 green:210/255.0 blue:245/255.0 alpha:1.0]];
    navi2.tabBarItem.title = @"收藏";
    navi2.tabBarItem.image = [UIImage imageNamed:@"4.png"];
    [array addObject:navi2];
    [myView release];
    
    
    UITabBarController * tab = [[UITabBarController alloc] init];
    tab.viewControllers = array;
    [_window setRootViewController:tab];
    [tab release];
    
    [NSThread sleepForTimeInterval:2];
    
    
    return YES;
}

- (void)didReceiveWeiboResponse:(WBBaseResponse *)response
{
    
}

// 禁止横屏
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [application beginBackgroundTaskWithExpirationHandler:nil];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [WeiboSDK handleOpenURL:url delegate:self];
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [WeiboSDK handleOpenURL:url delegate:self ];
}

@end
